package com.niuke;

import java.util.Scanner;

/**
 * @ClassName : HJ65
 * @Author : kele
 * @Date: 2023/4/2 14:35
 * @Description :
 */
public class HJ65 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {

            String str_short = in.nextLine();
            String str_long = in.nextLine();
            String tmp = str_short;

            if (str_long.length() < str_short.length()) {
                str_short = str_long;
                str_long = tmp;
            }

            //动态规划解决一下子
            int m = str_short.length();
            int n = str_long.length();

            int[][] dp = new int[m][n];
            int max = 0;
            int index = 0;

            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    if (str_short.charAt(i) == str_long.charAt(j)) {
                            if(i - 1 < 0 || j - 1 < 0){
                                dp[i][j] = 1;
                            }else{
                                dp[i][j] = dp[i - 1][j - 1] + 1;
                                if (max < dp[i][j]) {
                                    max = dp[i][j];
                                    index = i;
                                }
                            }
                    }

                }
            }

            System.out.println(str_short.substring(index - max + 1, index + 1));
        }

    }
}
